﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Windows.UI;


namespace GoEasy
{
    public partial class PlaceDetail : PhoneApplicationPage
    {
        RequestCommonFunction request;
        public PlaceDetail()
        {
            InitializeComponent();
            init();
        }

        private void init()
        {
        }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            // request data
            ProgressBarRequest.Visibility = System.Windows.Visibility.Visible;
            request = new RequestCommonFunction();
            request.Request(@"http://54.243.244.187:8090/Services/Login", "username=ducnd&password=123");
            request.RequestDone += new ChangedEventHandler(Request_Done); 
        }
        /// <summary>
        /// active when request done
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Request_Done(object sender, EventArgs e,dynamic Respone)
        {
            //Console.WriteLine("This is called when the event fires.");
            txtTest.Text = Respone.result_code;
            ProgressBarRequest.Visibility = System.Windows.Visibility.Collapsed;
        }
        /// <summary>
        /// khi chuyen sang man hinh khac -> huy het cac doi tuong
        /// </summary>
        /// <param name="e"></param>
        protected override void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e)
        {
            request.RequestDone -= new ChangedEventHandler(Request_Done);
            request = null;
        }

    }
}